<template>
	<view class="content" v-if="show==1" >
		<view class="header">
		    <view class="header_1">
		      <view class="avatar">
		        <image :src="user.avatar" mode='aspectFill'></image>
		      </view>
		      <view class="nickname" v-if="user.is_teacher==1">
		        <view class="nick">{{user.id}}-{{user.nickname}}</view>
		        <view class="level">{{user.cate}}-{{user.cate2}}</view>
				<template v-if="user.sm==0">
				<view class="level" v-if="user.is_real==1">
					<text v-if="user.status==4">已注销</text>
					<text v-if="user.status==3">注销申请中</text>
					<text v-if="user.status==2">已封号</text>
					<text v-if="user.status==1 && user.is_end==0">已店铺认证</text>
					<text v-if="user.status==1 && user.is_end==1">已到期</text>
					<text style="margin-left:10px;">到期时间：{{user.endtime}}</text>
				</view>
				<view class="level" v-if="user.is_real==0">
					<text>等待店铺认证</text>
					<text style="margin-left:10px;">到期时间：{{user.endtime}}</text>
				</view>
				</template>
				<template v-if="user.sm==1">
				<view class="level">
					<text>重新店铺认证</text>
					<text style="margin-left:10px;">到期时间：{{user.endtime}}</text>
				</view>
				</template>
		      </view>
			  
			  <view class="nickname" v-if="user.is_teacher==0">
			  	<view class="nick" style="height:70px;line-height: 70px;">
				{{user.nickname}}
				<view class="kuaisuruzhu" @click="ruzhu" v-if="user.is_teacher==0">快速入驻</view>
				</view>
			  </view>
		    </view>
		</view>
		<view class="fenxian hg5"></view>
		  <view class="order">
			<view class="dao" @click="url" data-url="/pages/teacher/shiming">
				<image src="../../static/laoshi/shiming.png" class="tubiao" mode="aspectFit"></image>
				<view class="dao2">店铺认证</view>
			</view>
			<view class="dao" @click="url" data-url="/pages/teacher/info">
				<image src="../../static/laoshi/xiugai.png" class="tubiao" mode="aspectFit"></image>
				<view class="dao2">修改资料</view>
			</view>
			<view class="dao" v-if="user.status<4 && user.is_teacher==1" @click="zhuxiao">
				<image src="../../static/laoshi/zhuxiao.png" class="tubiao" mode="aspectFit"></image>
				<view class="dao2">注销师傅</view>
			</view>
			<view class="dao" v-if="user.status==4 && user.is_teacher==1" @click="jihuo">
				<image src="../../static/laoshi/jihuo.png" class="tubiao" mode="aspectFit"></image>
				<view class="dao2">激活师傅</view>
			</view>
			<view class="dao" v-if="user.is_teacher==1" @click="url" data-url="/pages/teacher/xufei">
				<image src="../../static/laoshi/xufei.png" class="tubiao" mode="aspectFit"></image>
				<view class="dao2">到期续费</view>
			</view>
		  </view>
		<view v-if="is_gh==true" style="width:100%;">
		<view class="geng"></view>
		<view class="geng2">
			<view class="geng3">
				<text>支付</text>
				<image @click="gengh" src="../../static/cha.png" mode="aspectFit"></image>
			</view>
			<!-- #ifdef APP-PLUS -->
			<view class="geng4" v-if="zdtype==0">
				<view class="geng5">支付方式</view>
				<view class="geng6">
					<radio-group @change="moren2" style="text-align: right;line-height: 45px;">
						<label style="margin-right: 30px;">
							<radio value="2" color="#05c160" :checked="paytype==2" style="transform:scale(0.7)" />支付宝支付
						</label>
						<label>
							<radio value="1" color="#05c160" :checked="paytype==1" style="transform:scale(0.7)" />微信支付
						</label>
					</radio-group>
				</view>
			</view>
			<!-- #endif -->
			<view class="geng4">
				<view class="geng5">支付金额</view>
				<view class="geng6" style="line-height: 40px;text-align: right;font-size: 1.1rem;color:red;">
					{{zdtype==1?'㉿':'￥'}}{{user.jh_price}}
				</view>
			</view>
			<!-- #ifdef MP-WEIXIN -->
			<view class="geng8" @click="shouquan">立即支付</view>
			<!-- #endif -->
			<!-- #ifndef MP-WEIXIN -->
			<view class="geng8" @click="zhifu" v-if="zdtype==0">立即支付</view>
			<view class="geng8" @click="zhifu" v-if="zdtype==1 && user.money>=user.jh_price">立即支付</view>
			<view class="geng8" @click="chong" v-if="zdtype==1 && user.money<user.jh_price">课券余额不足，去充值</view>
			<!-- #endif -->
		</view>
		</view>
	</view>
</template>

<script>
	var app=getApp();
	export default {
		data() {
			return {
				show:0,
				uid:0,
				zdtype:0,
				is_gh:false,
				wxcode:'',
				sheight:0,
				paytype:0,
				user:[]
			}
		},
		onShow() {
			const uid = uni.getStorageSync('uid');
			if(app.isBlank(uid)==true){
				//uni.removeStorageSync('js_type');
				uni.reLaunch({
				    url: "/pages/index/index"
				});
				return false;
			}
			var that=this;
			uni.getSystemInfo({
			    success: function (res) {
					if(res.platform=='ios'){
						//that.zdtype=1;
					}
			    }
			});
			
			// #ifdef MP-WEIXIN
			this.paytype=1;
			// #endif
			this.uid=uid;
			this.getdata();
		},
		methods: {
			getdata(){
				var that=this;
				uni.request({
				    url: app.globalData.url+"laoshi/center",
					method:"POST",
					dataType:"json",
					header: {
					    'content-type': 'application/x-www-form-urlencoded'
					},
				    data: {uid:that.uid},
				    success: (res) => {
						uni.hideLoading();
						if(res.data.code==1){
							that.user=res.data.data.user
							that.show=1;
						}else if(res.data.code==4000){
							uni.removeStorageSync('uid');
							uni.removeStorageSync('js_type');
							uni.reLaunch({
							    url: "/pages/index/index"
							});
						}else if(res.data.code==4100){
							uni.removeStorageSync('js_type');
							uni.reLaunch({
							    url: "/pages/user/index"
							});
						}else{
							uni.reLaunch({
							    url: '/pages/index/index'
							});
							return false;
						}
				    }
				});
			},
			smoney(m){
				this.user.money=m;
			},
			chong(){
				uni.navigateTo({
				    url: "/pages/user/chong?type=1"
				});
			},
			jihuo(){
				if(this.zdtype==0){
					var t="激活师傅需要支付￥"+this.user.jh_price;
				}else{
					var t="激活师傅需要支付㉿"+this.user.jh_price;
				}
				var that=this;
				uni.showModal({
				    title: '确定要激活吗？',
				    content: t,
				    success: function (res) {
				        if (res.confirm) {
				            that.is_gh=true;
				        }
				    }
				});
			},
			moren2(e){
				this.paytype=e.detail.value;
			},
			shouquan(){
				var that=this;
				uni.showLoading({
				    title: '请求中'
				});
				uni.login({
				  provider: 'weixin',
				  success: function (loginRes) {
					that.wxcode=loginRes.code;
					that.zhifu(1);
				  },
				  fail(){
					  uni.showToast({
					      title: '信息异常，请重试',
							icon:'none',
					      duration: 1000
					  });
				  }
				});
			},
			zhifu(t=0){
				var that=this;
				if(t==0){
				uni.showLoading({
				    title: '请求中'
				});
				}
				var type='wxxcx';
				// #ifdef APP-PLUS
				type='app';
				if(this.zdtype==0 && this.paytype==0){
					uni.showToast({
					    title: '请选择支付方式',
						icon:'none',
					    duration: 1000
					});
					return false;
				}
				// #endif
				if(this.zdtype==1){
					this.paytype=3;
				}
				
				uni.request({
				    url: app.globalData.url+"laoshi/jihuo_pay",
					method:"POST",
					dataType:"json",
					header: {
					    'content-type': 'application/x-www-form-urlencoded'
					},
				    data: {uid:that.uid,paytype:that.paytype,type:type,code:that.wxcode,zdtype:that.zdtype},
				    success: (res) => {
						uni.hideLoading();
						if(res.data.code!=1){
							uni.showToast({
							    title: res.data.msg,
								icon:'none',
							    duration: 1500
							});
							return false;
						}
						
						if(res.data.data.is_pay==0){
							uni.showToast({
							    title: "激活成功",
								icon:'success',
							    duration: 1000
							});
							that.gengh();
							that.user.status=1;
							return false;
						}
						
						if(type=="wxxcx"){
							uni.requestPayment({
							    provider: 'wxpay',
							    timeStamp: res.data.data.pay.timeStamp,
								nonceStr: res.data.data.pay.nonceStr,
								package: res.data.data.pay.package,
								signType: 'MD5',
								paySign: res.data.data.pay.paySign,
							    success: function (res) {
							        uni.showToast({
							            title: "激活成功",
							        	icon:'success',
							            duration: 1000
							        });
							        that.user.status=1;
									that.gengh();
							    },
							    fail: function (err) {
							        console.log('fail:' + JSON.stringify(err));
							    }
							});
						}else if(type=="app"){
							if(that.paytype==1){
								uni.requestPayment({
								    provider: 'wxpay',
								    orderInfo: {
										"appid": res.data.data.pay.appid,
										"noncestr": res.data.data.pay.noncestr, // 随机字符串
										"package": res.data.data.pay.package,        // 固定值
										"partnerid": res.data.data.pay.partnerid,      // 微信支付商户号
										"prepayid": res.data.data.pay.prepayid, // 统一下单订单号 
										"timestamp": res.data.data.pay.timestamp,        // 时间戳（单位：秒）
										"sign": res.data.data.pay.sign // 签名，这里用的 MD5 签名
									},
								    success: function (res) {
								        uni.showToast({
								            title: "激活成功",
								        	icon:'success',
								            duration: 1000
								        });
								        that.user.status=1;
										that.gengh();
								    },
								    fail: function (err) {
								        console.log('fail:' + JSON.stringify(err));
								    }
								});
							}else{
								uni.requestPayment({
								    provider: 'alipay',
								    orderInfo: res.data.data.pay,
								    success: function (res) {
								        uni.showToast({
								            title: "激活成功",
								        	icon:'success',
								            duration: 1000
								        });
								        that.user.status=1;
										that.gengh();
								    },
								    fail: function (err) {
								        console.log('fail:' + JSON.stringify(err));
								    }
								});
							}
						}
				    }
				});
			},
			gengh(){
				this.is_gh=!this.is_gh;
			},
			zhuxiao(){
				var that=this;
				if(this.user.status==3){
					uni.showToast({
					    title: "您的注销申请正在审核中",
						icon:'none',
					    duration: 1500
					});
					return false;
				}
				uni.showModal({
				    content: '请确认订单已完结，账户余额已全部提现',
				    success: function (res) {
				        if (res.confirm) {
				            uni.showModal({
				                content: '当前正在提交注销师傅操作，请您再次确认',
				                success: function (res2) {
				                    if (res2.confirm) {
				                        uni.showLoading({
				                            title: '注销中'
				                        });
				                        uni.request({
				                            url: app.globalData.url+"laoshi/zhuxiao",
				                        	method:"POST",
				                        	dataType:"json",
				                        	header: {
				                        	    'content-type': 'application/x-www-form-urlencoded'
				                        	},
				                            data: {uid:that.uid},
				                            success: (res) => {
				                        		uni.hideLoading();
				                        		if(res.data.code!=1){
				                        			uni.showToast({
				                        			    title: res.data.msg,
				                        				icon:'none',
				                        			    duration: 1500
				                        			});
				                        			return false;
				                        		}
				            					that.user.status=3;
				                        		uni.showToast({
				                        		    title: res.data.msg,
				                        			icon:'none',
				                        		    duration: 1000
				                        		});
				                            }
				                        });
				                    }
				                }
				            });
				        }
				    }
				});
			},
			yonghu(){
				uni.setStorageSync('js_type', 1);
				
				uni.reLaunch({
				    url: "/pages/user/index"
				});
			},
			ding(e){
				var s=e.currentTarget.dataset.id;
				uni.setStorageSync('status', s);
				
				uni.reLaunch({
				    url: "/pages/order/index"
				});
			},
			url(e){
				var url=e.currentTarget.dataset.url;
				var id=e.currentTarget.dataset.id;
				const uid = uni.getStorageSync('uid');
				if(app.isBlank(uid)==true && id==1){
					uni.navigateTo({
					    url: '/pages/login/login'
					});
					return false;
				}
				if(this.user.is_teacher!=1){
					uni.showToast({
					    title: '请您先入驻',
						icon:'none',
					    duration: 1000
					});
					return false;
				}
				if(this.user.status==4){
					uni.showToast({
					    title: '请先激活师傅',
						icon:'none',
					    duration: 1000
					});
					return false;
				}
				uni.navigateTo({
				    url: url
				});
			},
			tui(){
				var pages = getCurrentPages(); //当前页面栈
				if (pages.length > 1){
					uni.navigateBack({
						delta: 1
					});
				}else{
					uni.reLaunch({
					    url: '/pages/teacher/index'
					});
				}
			},
			kefu(){
				this.is_kf=!this.is_kf;
			},
			weixin(){
				setClipboardData(this.site.weixin);
				uni.showToast({
				    title: '复制成功！',
				    duration: 1000
				});
			},
			qq(){
				setClipboardData(this.site.qq);
				uni.showToast({
				    title: '复制成功！',
				    duration: 1000
				});
			},
			tel(){
				uni.makePhoneCall({
				    phoneNumber: this.site.tel
				});
			},
			ruzhu(){
				uni.navigateTo({
				    url: '/pages/user/ruzhu'
				});
			},
			info(){
				const uid = uni.getStorageSync('uid');
				if(app.isBlank(uid)==true){
					uni.navigateTo({
					    url: '/pages/login/login'
					});
					return false;
				}
				uni.navigateTo({
				    url: '/pages/user/info'
				});
			}
		}
	}
</script>

<style>
	.top{padding: 0px 15px;height:45px;overflow: hidden;background-color: #ededed;}
	.top2{width:15%;height:45px;float: left;}
	.top2 image{width:21px;height:21px;margin-top: 12px;}
	.top3{width:70%;height:45px;float: left;line-height: 45px;font-size: 1rem;color:#000;text-align: center;font-weight: 550;}
	.top4{width:15%;height:45px;float: left;}
	.top4 image{width:21px;height:21px;margin-top: 12px;float: right;}
	.kuaisuruzhu{width:90px;height:35px;line-height: 35px;text-align: center;background-color: #0532c4;color:#fff;border-radius: 4px;margin-top: 18px;float: right;}
	.geng8{width:80%;height:35px;line-height: 35px;background-color: #05c160;margin: 0 auto;color: #fff;text-align: center;border-radius: 3px;position: absolute;bottom: 10px;left: 50%;margin-left: -40%;}
	.geng7{width:30%;height:30px;line-height: 30px;text-align: center;background-color: #05c160;color:#fff;border-radius: 3px;margin-top: 5px;float: right;font-size: 0.75rem;margin-left: 5px;}
	.geng6 input{width:60%;height:40px;float: left;font-size: 0.875rem;}
	.geng6{width:100%;height:40px;flex:1;}
	.geng5{width:80px;height:40px;line-height: 40px;}
	.geng4{width:94%;padding: 0px 3%;height:40px;border-bottom: 1px rgb(245, 245, 245) solid;display: flex;}
	.geng3 image{width:20px;height:20px;float: right;margin-top: 10px;}
	.geng3 text{font-weight: 550;}
	.geng3{width:94%;padding: 0px 3%;height:40px;line-height: 40px;border-bottom: 1px rgb(245, 245, 245) solid;}
	.geng2{width:100%;height:200px;position: fixed;bottom: 0px;background-color: #fff;z-index: 9999;}
	.geng{width:100%;height:100vh;position: fixed;top:0px;z-index: 9995;background-color: #000000;opacity: 0.7;}
	.fenxiang{width:20px;height:20px;}
	.dao2{width:100%;height:30px;line-height: 30px;font-size: 0.9rem;}
	.tubiao{width:35px;height:35px;}
	.dao{width:50%;float: left;text-align: center;margin-top: 30px;}
	
	.header{width:100%;height:100px;background-color:#fff;position: relative;}
	.header_1{width:100%;height:100px;overflow: hidden;}
	.avatar{width:25%;float: left;text-align: center;height:100px;}
	.avatar image{width:70px;margin-top: 15px;border-radius: 50%;height:70px;}
	.nickname{width:70%;float: left;height:100px;overflow: hidden;}
	.nick{width:100%;height:30px;line-height: 30px;margin-top: 13px;font-size: 1rem;color:#000;overflow: hidden;}
	.nick2{width:70%;height:100px;line-height: 100px;font-size: 1.1rem;color:#000;overflow: hidden;float: left;}
	.nick3{width:25%;height:33px;border:1px #000 solid;border-radius: 5px;text-align: center;line-height: 33px;color:#000;float: right;margin-top: 32.5px;}
	.level{width:100%;height:20px;line-height: 20px;color:#000;font-size: 0.8rem;font-weight: 550;}
	.site{width:15%;float: left;height:100px;text-align: center;}
	.site image{width:25px;margin-top: 15px;}
	.bai{width:100%;height:50px;background-color: #fff;opacity: 0.15;position: absolute;bottom: 0px;}
	.yue{width:100%;height:50px;position: absolute;bottom: 0px;overflow: hidden;}
	.money{width:33.33%;float: left;}
	.money_1{width:100%;text-align: center;height:25px;line-height: 30px;font-size: 1.1rem;color:#fff;margin-top: 1px;}
	.money_2{width:100%;text-align: center;height:20px;line-height: 20px;color:#fff;}
	
	.zhong{width:100%;padding: 15px 0px;overflow: hidden;}
	.zhong_1{width:49%;float: left;overflow: hidden;}
	.level_img{width:40%;float: left;text-align: right;}
	.level_img image{width:40px;margin-right: 10px;}
	.level_title{width:60%;float: left;}
	.user_c{width:100%;height:22px;line-height: 28px;color:#f08a04;font-size: 0.9rem;overflow: hidden;}
	.shuo{width:100%;height:18px;line-height: 22px;color:#999;font-size: 0.6rem;overflow: hidden;}
	
	.user_c2{width:100%;height:22px;line-height: 28px;color:#666;font-size: 0.9rem;overflow: hidden;}
	.zhong_2{width:2%;float: left;text-align: center;}
	.zhong_2 view{width:1px;height:40px;background-color: #eee;}
	.zhong_3{width:49%;float: left;}
	.advert{width:96%;padding: 8px 2%;background-color: rgb(245, 245, 245);}
	.advert image{width:100%;border-radius: 20px;}
	
	.order{width:100%;margin-top: 30px;}
</style>
